grammar BasicAlgebraEqu;

options {
  language = Java;
  output = AST;
  ASTLabelType = CommonTree;
}

tokens{
  NEGATION;
}

@header {
  package algebra;
}

@lexer::header {
  package algebra;
}

evaluator 
  : assignment* expression EOF!
  /*| factor EOF!*/
  ;

assignment
  : IDENT ':=' expression ';'
  ;

//expressions
term
  : IDENT
  |  '('! expression ')'!
  | INTEGER
  | POLY
  | POLY2
  | VARIABLE
  ;

exponent
	: term ('^'^ term)*
	;

unary
  : ('+'! | negation^ )* exponent
  ;

negation
  :  '-' -> NEGATION
  ;

mult
  : unary (('*'^ | '/'^) unary)*
  ;

expression
  : mult (('+'^ | '-'^ | '='^) mult)*
  ;

fragment LETTER : ('a'..'w' | 'A'..'W');
fragment DIGIT : '0'..'9';
VARIABLE : 'x' | 'y' | 'z' | 'X' | 'Y' | 'Z';
INTEGER : DIGIT+;
IDENT  : LETTER (LETTER | DIGIT)*;
POLY : '<poly>';
POLY2 : '<poly2>';
WS: (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel = HIDDEN;};
